<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{margin:0px;padding:0px;list-style: none}
        ul{width:950px;margin:10px auto}
        ul li {width:300px;height:300px;float:left;border:1px solid red;margin:5px;}
        img{width:300px;height:300px;}
        body{height:1500px;}
    </style>
</head>
<body>
    <ul>
        <li><img _src="image/1.jpg" alt=""></li>
        <li><img _src="image/2.jpg" alt=""></li>
        <li><img _src="image/3.jpg" alt=""></li>
        <li><img _src="image/4.jpg" alt=""></li>
        <li><img _src="image/img7.jpg" alt=""></li>
        <li><img _src="image/img8.jpg" alt=""></li>
        <li><img _src="image/img9.jpg" alt=""></li>
        <li><img _src="image/img10.jpg" alt=""></li>
        <li><img _src="image/img11.jpg" alt=""></li>
        <li><img _src="image/img12.jpg" alt=""></li>
    </ul>
    <script>
        //1、获取所有待加载的图片
        var img = document.getElementsByTagName("img");
        //3、浏览器发生滚动
        window.onscroll = function(){
            //4、获取滚动的Top距离
            var top = document.documentElement.scrollTop || document.body.scrollTop;
            //2、循环获取每一张图片
            for(var i = 0;i<img.length;i++){
                var img_top = img[i].offsetTop;
                var eyehheight = document.documentElement.clientHeight;
                if(img_top<=top+eyehheight){
                    //获取元素的自定义属性??
                    img[i].src = img[i].getAttribute("_src");
                    console.log(img[i].src);
                }
            }
        }
        //好处：降低了带宽，以及流量，减少了服务器的压力，而且是用户浏览到哪里就加载到哪里
    </script>
</body>
</html>